/**
 * @Author: wilmerxu
 * @Description: 内容js
 * @Date: 2020/7/28 12:10
 */
import {Message, MessageBox} from 'element-ui';
import {initElementUi} from '../libs/element-ui';
import Storage from '../libs/storage';
// 初始化element-ui
initElementUi();

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  const {cmd, value} = request;
  Message({
    type: 'success',
    message: value,
  });

  sendResponse(true);
});

const init = async () => {
  console.log('wilmer chrome extension init');
  const isChromeExtInit = await Storage.get('w_chrome_ext_init');
  console.log('w_chrome_ext_init:', isChromeExtInit);
  if (!isChromeExtInit) {
    MessageBox.confirm('<div>智能插件未登录</div><div>请先登录！</div>', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
      dangerouslyUseHTMLString: true,
    }).then(async () => {
      await Storage.set('w_chrome_ext_init', true);
      Message({
        type: 'success',
        message: '登录成功',
      });
    }).catch(() => {
      Message({
        type: 'error',
        message: '已取消登录',
      });
    });
  }
};

init();
